let handleTouchStart, handleTouchMove, handleTouchEnd
export default {
  mounted (el, binding) {
    let pressTimer = null
    let startX, startY
    const onLongPress = () => {
      binding.value && typeof binding.value === 'function' && binding.value({
        x: startX,
        y: startY
      })
    }

    handleTouchStart = (e) => {
      startX = e.touches[0].clientX
      startY = e.touches[0].clientY
      pressTimer = setTimeout(onLongPress, 500)
    }
    handleTouchMove = (e) => {
      clearTimeout(pressTimer)
    }
    handleTouchEnd = (e) => {
      clearTimeout(pressTimer)
    }

    el.addEventListener('touchstart', handleTouchStart, {
      passive: false
    })

    el.addEventListener('touchmove', handleTouchMove, {
      passive: false
    })

    el.addEventListener('touchend', handleTouchEnd, {
      passive: false
    })
  },
  unmounted (el) {
    el.removeEventListener('touchstart', handleTouchStart)
    el.removeEventListener('touchmove', handleTouchMove)
    el.removeEventListener('touchend', handleTouchEnd)
  }
}
